package com.xz.xzutils;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import com.xz.xzutils.icons.MyIcons;
import com.xz.xzutils.module.toolwindow.tabs.BaseTab;
import com.xz.xzutils.module.toolwindow.tabs.FormaterTab;
import com.xz.xzutils.module.toolwindow.tabs.SqlParserTab;
import com.xz.xzutils.test.TestTab;
import org.jetbrains.annotations.NotNull;

/**
 * <p>
 *
 * </p>
 *
 * @author DONG.WANG17@HAND-CHINA.COM
 * @since 2025-01-03 14:56
 */
public class XzUtilsWindowFactory implements ToolWindowFactory, DumbAware {
    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
        toolWindow.setIcon(MyIcons.PLUGIN_ICONS);
        FormaterTab formaterTab = new FormaterTab(project);
        SqlParserTab sqlParserTab = new SqlParserTab(toolWindow);
        //TestTab testTab = new TestTab(project);
        this.addTab(toolWindow, formaterTab, true);
        this.addTab(toolWindow, sqlParserTab, false);
        //this.addTab(toolWindow, testTab, false);
    }

    private <Tab extends BaseTab> void addTab(@NotNull ToolWindow toolWindow, @NotNull Tab tab, boolean isLockable){
        ContentFactory contentFactory = ContentFactory.getInstance();
        Content content = contentFactory.createContent(tab.getJComponent(), tab.getTabName(), isLockable);
        toolWindow.getContentManager().addContent(content);
    }
}